package org.zfes.snowier.xyz.analysis.queue;

import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import com.google.common.collect.Lists;

public class SnowierBlockQueue  extends LinkedBlockingQueue{
	
	 private final ReadWriteLock lock = new ReentrantReadWriteLock();
	 private final Lock readLock = lock.readLock();
	 
	 private String topic;

	public SnowierBlockQueue(String topic) {
		super();
		this.topic = topic;
	}
	
	public List<Object> poll(int count) {
		//long stamp = sl.readLock();
		
		try {
			this.readLock.lock();
			int i=0;
			List<Object> dataList=Lists.newArrayList();
			Object data = super.poll();
			if(data==null) {
				return dataList;
			}
			dataList.add(data);
			
			
			int coun=count-1;
			while(i < coun && data!=null) {
				data = super.poll();
				if(data!=null) {
					dataList.add(data);
				}
				i++;
			}
			return dataList;
		}finally {
			this.readLock.unlock();
		//	 sl.unlockRead(stamp);
		}
	}
	



	
	
	
}
